import { HttpSeriveProvider } from './../http-serive/http-serive';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';


/*
  Generated class for the ComSeriveProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class ComSeriveProvider {
  public headers;

  apiLogin = 'user/login'; // 登录功能
  apiRegisterCode = 'message/send/register/'; // 短信注册
  apiCheckCode = 'message/code'; // 验证码匹配
  apiCheckPhoneInfo = 'user/info/phone/'; // 手机号验证
  apiRegister = 'user/register'; // 用户注册
  apuGetUserInfo = 'user/info/userCode'; // 获取用户信息
  apiExit = 'user/exit'; // 退出登录
  apiPhoto = 'photo/upload'; // 图片接口
  apichangePassword = 'user/password';
  apiChangePasswordCode = 'message/send/changepassword/'; // 短信改密
  apiClass = 'class/get?param=new Date()';

  constructor(public http: HttpClient, public httpService: HttpSeriveProvider) {
    console.log('Hello ComSeriveProvider Provider');
    this.headers = new HttpHeaders();
    this.headers = this.headers.set('Content-Type', 'text/plain');
  }

  // 注册短信
  registerCode(phone) {
    return this.httpService.get(
      this.httpService.api + this.apiRegisterCode + phone
    );
  }

  // 验证码验证
  checkCode(body) {
    return this.httpService.post(
      this.httpService.api + this.apiCheckCode,
      body,
      { headers: this.headers }
    );
  }

  // 检查手机是否注册
  checkPhoneInfo(phone) {
    return this.httpService.get(
      this.httpService.api + this.apiCheckPhoneInfo + phone
    );
  }

  // 注册
  userRegister(body) {
    return this.httpService.post(
      this.httpService.api + this.apiRegister,
      body,
      { headers: this.headers }
    );
  }

  // 用户登录
  userLogin(body) {
    return this.httpService.post(this.httpService.api + this.apiLogin, body, {
      headers: this.headers
    });
  }

  // 图片上传
  uploadPhoto(body) {
    return this.httpService.post(this.httpService.api + this.apiPhoto, body, {
      headers: this.headers
    });
  }

  // 修改密码短信
  changePasswordCode(phone) {
    return this.httpService.get(
      this.httpService.api + this.apiChangePasswordCode + phone
    );
  }

  // 修改密码
  changPassword(user) {
    return this.httpService.post(
      this.httpService.api + this.apichangePassword,
      user
    );
  }

  getClass() {
    return this.httpService.get(this.httpService.api + this.apiClass);
  }

  

}
